package DesignMode.observer;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class RealSubject implements Subject{
    private List<Observer> list = new CopyOnWriteArrayList<>();

    @Override
    public void attach(Observer observer) {
        list.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        list.remove(observer);
    }

    @Override
    public void notifyChange() {
        list.forEach(item->{
            item.update();
        });
    }
}
